package cn.iocoder.yudao.module.bpm.dal.mysql.taggroupinfo;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.bpm.dal.dataobject.taggroupinfo.BpmTagGroupInfoDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.taginfo.BpmTagInfoDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.*;
import cn.iocoder.yudao.module.bpm.controller.admin.taggroupinfo.vo.*;

/**
 * 标签组信息 Mapper
 *
 * @author 韩佳乐
 */
@Mapper
public interface BpmTagGroupInfoMapper extends BaseMapperX<BpmTagGroupInfoDO> {

    default PageResult<BpmTagGroupInfoDO> selectPage(BpmTagGroupInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BpmTagGroupInfoDO>()
                .likeIfPresent(BpmTagGroupInfoDO::getName, reqVO.getName())
                .betweenIfPresent(BpmTagGroupInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BpmTagGroupInfoDO::getId));
    }

    @Select("SELECT distinct t1.id,\n" +
            "       t1.name \n" +
            "FROM bpm_tag_group_info t1\n")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(property = "children", javaType = List.class,column = "id",many = @Many(select ="selectTagsByGroupId"))
    })
    List<BpmAllTagGroupInfoVO> selectAllTagChildren();

    @Select("SELECT t2.id AS tagId, t2.name AS tagName " +
            "FROM bpm_tag_info t2 " +
            "WHERE t2.group_id = #{groupId}")
    List<BpmAllTagGroupInfoVO.Tags> selectTagsByGroupId(Long groupId);


}